package web.modalWindow;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.IHeaderContributor;
import org.apache.wicket.util.string.AppendingStringBuffer;

/**
 * Una Modal Window Normal, pero se cierra al apretar ESC
 */
public class ModalWindowPersonalizada extends ModalWindow implements IHeaderContributor {
	private static final long serialVersionUID = 1L;

	public ModalWindowPersonalizada(String id) {
		super(id);
	}

	public void show(final AjaxRequestTarget target) {
		if (!isShown()) {
			final AppendingStringBuffer buffer = new AppendingStringBuffer(500);
			buffer.append(
			"function mwClose(ev) {\n" +
			"	var code = ev.keyCode || ev.which;\n" +
			"	if (code == 27) { " +
					getCloseJavacript() +
			"	};" +
			"}");
			buffer.append("jQuery(document).keypress(mwClose);\n");
			target.appendJavaScript(buffer.toString());
		}
		super.show(target);
	}
}